package com.xlabs.client.DTO;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import com.google.gwt.user.client.rpc.IsSerializable;

/**
 * Transfer data transfer object.
 */
public class TransferDTO implements Serializable, IsSerializable
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1935216748847080773L;
	
	/**
	 * No argument constructor to comply with GWT specification.
	 */
	public TransferDTO()
	{
		super();
	}
	
	/**
	 * String value map.
	 */
	private HashMap<String, String> stringValueMap = new HashMap<String, String>(); 

	/**
	 * Boolean value map.
	 */
	private HashMap<String, Boolean> booleanValueMap = new HashMap<String, Boolean>();
	
	/**
	 * List value map.
	 */
	private HashMap<String, ArrayList<EntityDTO>> entityListValueMap = new HashMap<String, ArrayList<EntityDTO>>(); 

	/**
	 * Question list key.
	 */
	public static final String RESULT_KEY = "questionArray";

	/**
	 * Has Previous page questions key.
	 */
	public static final String HAS_PREV_QUESTIONPAGE_KEY = "hasPrev";

	/**
	 * Has Next page questions key.
	 */
	public static final String HAS_NEXT_QUESTIONPAGE_KEY = "hasNext";
	
	/**
	 * Next page question start time index key.
	 */
	public static final String NEXT_PAGE_QUESTION_START_TIME_INDEX_KEY = "nextPageQuestionStartTimeIndexKey";
	
	/**
	 * Left direction for queries.
	 */
	public static final int LEFT_DIRECTION = 0;

	/**
	 * Right direction for queries.
	 */
	public static final int RIGHT_DIRECTION = 1;

	/**
	 * Adds a key value pair to the transfer object.
	 * 
	 * @param key
	 *            string key.
	 * @param value
	 *            object value.
	 */
	@SuppressWarnings("unchecked")
	public void addKeyValue(String key, Object value)
	{
		if (value instanceof Boolean)
		{
			booleanValueMap.put(key, (Boolean) value);
		}
		else if (value instanceof String)
		{
			stringValueMap.put(key, (String) value);
		}
		else if (value instanceof ArrayList<?>)
		{
			entityListValueMap.put(key, (ArrayList<EntityDTO>) value);	    
		}
	}

	/**
	 * Gets value for the given key.
	 * 
	 * @param key
	 *            string key.
	 * @return corresponding value in value map for the given key.
	 */
	public Object getValue(String key)
	{
		if (booleanValueMap.containsKey(key))
		{
			return booleanValueMap.get(key);
		}
		else if (stringValueMap.containsKey(key))
		{
			return stringValueMap.get(key);
		}
		else if (entityListValueMap.containsKey(key))
		{
			return entityListValueMap.get(key);
		}
		
		return null;
	}
}
